<template lang="">
  <div class="center">
    <div class="main" style="border: 1px solid #fff;background-color: #fff;border-radius: 10px;">
      <div class="top" style="border: 0px solid #000;background-color: #fff;border-radius: 10px;margin: 30px 50px;">
        <div class="title"
          style="text-align: left;margin-left: 0px;margin-top:30px;border-left: 3px solid #fe0100;width: 100px;height: 25px;">
          <h3 style="color:#fe0100 ;font-weight: 500;font-size: 18px;padding-left: 15px;">合同摘要</h3>
        </div>
        <div v-if="type === 1" class="bx" style="border: 0px solid #000;width: 550px;margin: 40px 20px;">
          <el-form ref="contractData" :model="contractData" label-width="130px">
            <el-form-item label="合同类型">
              <el-radio-group v-model="contractData.contractType" style="width: 500px;margin-left: 0px;">
                <el-radio label="0">销售合同</el-radio>
                <el-radio label="1">采购合同</el-radio>
                <el-radio label="2">合作协议</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="关联项目">
              <el-select v-model="contractData.salesId" placeholder="请选择商机" clearable>
                <el-option v-for="(item,index) in changeList" :key="index" :label="item.businessName"
                  :value="item.salesId"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="合同名称">
              <el-input placeholder="请输入名称" v-model="contractData.contractName"></el-input>
            </el-form-item>
            <el-form-item label="主合同名称">
              <el-select v-model="contractData.parentId" clearable placeholder="请选择" clearable>
                <el-option v-for="item in contractList" :key="item.contractId" :label="item.contractName"
                  :value="item.contractId"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="合同编号">
              <el-input v-model="contractData.contractNumber"></el-input>
            </el-form-item>
            <el-form-item label="甲方">
              <el-input v-model="contractData.firstParty"></el-input>
            </el-form-item>
            <el-form-item label="甲方代表人">
              <el-input v-model="contractData.firstRepresentative"></el-input>
            </el-form-item>
            <el-form-item label="乙方">
              <el-input v-model="contractData.secondParty"></el-input>
            </el-form-item>
            <el-form-item label="乙方代表人">
              <el-input v-model="contractData.secondRepresentative"></el-input>
            </el-form-item>
            <el-form-item label="状态">
              <el-radio-group v-model="contractData.contractStatus" style="width: 500px;margin-left: 0px;">
                <el-radio label="0">待审批</el-radio>
                <el-radio label="1">已签订</el-radio>
                <el-radio label="2">已完成</el-radio>
                <el-radio label="3">已作废</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="负责人">
              <el-select v-model="contractData.principalId" placeholder="请选择负责人" @change="getUserList" clearable
                style="border:1px solid #b6b6b6;width: 300px;border-radius: 50px;overflow: hidden;" >
                <el-option v-for="(item,index) in userList3" :key="index" :label="item.realname" :value="item.userId">
                </el-option>
  
              </el-select>
            </el-form-item>
            <el-form-item label="客户">
              <el-select v-model="contractData.customId" placeholder="请选择客户" clearable>
                <el-option v-for="(item,index) in userList2" :key="item.userId" :label="item.username"
                  :value="item.userId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="合同总金额">
              <el-input v-model="contractData.contractAmount"></el-input>
            </el-form-item>
            <el-form-item label="合同内容">
              <el-input autosize type="textarea" v-model="contractData.remark"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button @click="updateContract()" type="danger" class="button">确定</el-button>
              <el-button @click="type = 0" type="danger" class="button">取消</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div v-else class="bx" style="border: 0px solid #000;width: 750px;margin: 40px 0px;">
          <ul style="list-style: none;padding: 0;margin:0;">
            <li v-model="contractData" style="text-align: left;margin-left: 15px">
              <p>
                <span class="title" style="margin-left: 30px;">合同类型 </span>
                <span class="blue" v-if="contractData.contractType == 0">销售合同</span>
                <span class="blue" v-if="contractData.contractType == 1">采购合同</span>
                <span class="blue" v-if="contractData.contractType == 2">合作协议</span>
              </p>
              <p>
                <span class="title" style="margin-left: 30px;">关联项目 </span>
                <span class="blue">{{contractData.businessName}}</span>
              </p>
              <p>
                <span class="title" style="margin-left: 65px;">客户</span>
                <span class="blue">{{contractData.customName}}</span>
              </p>
              <p>
                <span class="title" style="margin-left: 30px;">合同名称 </span>
                <span>{{contractData.contractName}}</span>
              </p>
              <p>
                <span v-if="contractData.parentId==''"></span>
                <span v-if="contractData.parentId==''"></span>
                <span class="title" style="margin-left: 14px;" v-if="contractData.parentId!=''" >主合同名称 </span>
                <span v-if="contractData.parentId!=''">{{contractData.parentName}}</span>
              </p>

              <p>
                <span class="title" style="margin-left: 30px;">合同编号 </span>
                <span>{{contractData.contractNumber}}</span>
              </p>
              <p>
                <span class="title" style="margin-left: 62px;">甲方 </span>
                <span>{{contractData.firstParty}}</span>
              </p>
              <p>
                <span class="title" style="margin-left: 15px;">甲方代表人 </span>
                <span>{{contractData.firstRepresentative}}</span>
              </p>
              <p>
                <span class="title" style="margin-left: 62px;">乙方 </span>
                <span>{{contractData.secondParty}}</span>
              </p>
              <p>
                <span style="margin-left: 15px;" class="title">乙方代表人 </span>
                <span>{{contractData.secondRepresentative}}</span>
              </p>
              <p>
                <span style="margin-left: 15px;" class="title">合同总金额 </span>
                <span>{{(parseFloat(contractData.contractAmount)).toLocaleString('zh-CN', { style: 'currency', currency:
                  'cny', currencyDisplay: 'symbol' })}}</span>
              </p>
              <p>
                <span class="title" style="margin-left: 65px;">状态</span>
                <span class="blue" v-if="contractData.contractStatus == 0">待审批</span>
                <span class="blue" v-if="contractData.contractStatus == 1">已签订</span>
                <span class="blue" v-if="contractData.contractStatus == 2">已完成</span>
                <span class="blue" v-if="contractData.contractStatus == 3">已作废</span>

              </p>

              <p>
                <span class="title" style="margin-left: 50px;">负责人</span>
                <span class="blue">{{contractData.principalName}}</span>
              </p>

              <p>
                <span class="title">合同签订日期</span>
                <span>{{moment(contractData.contractDate).format('YYYY/MM/DD ')}}</span>
              </p>
              <p>
                <span class="title">项目交付日期</span>
                <span>{{moment(contractData.dateDue).format('YYYY/MM/DD ')}}</span>
              </p>
              <p>
                <span class="title">时间轴</span>
                <span>
                  <el-steps :active="getScheduleNumber()" align-center finish-status="success">
                    <el-step v-for="(item,index) in scheduleList" :key="index"
                      :title="moment(item.receivableTime).format('YYYY/MM/DD ')" :description="item.title"></el-step>
                  </el-steps>

                </span>

              </p>
              <p style="border: 0px solid #000;width: 500px;">
                <span class="title"
                  style="color:#fe0100 ;font-weight: 500;font-size: 18px;padding-left: 15px;border-left: 3px solid #fe0100;margin-left: -10px;">合同内容</span><br>
              <pre
                style="border:0px solid #000;display: block;text-indent: 2em;font-family:Microsoft YaHei;
              font-size: 16px;line-height: 20px;width:1000px;white-space: pre-wrap;word-wrap: break-word">{{contractData.remark}}</pre>
              </p>
            </li>
          </ul>
          <el-button v-if="goBackCustomFlag == 1" @click="goBackCustom()" type="danger" class="button">返回</el-button>
          <el-button v-else @click="goBackP()" type="danger" class="button">返回</el-button>
          <el-button @click="type = 1" type="danger" class="button">编辑</el-button>
          <el-button style="width:150px" @click="dialogVisible = true" type="danger" class="button">添加合同进度</el-button>
          <el-upload class="upload-demo" action="http://192.168.2.75:9050/api/file/upload"
            :on-preview="uploadVideoProcess" multiple :on-success="handleVideoSuccess" :headers='importHeaders'
            :file-list="fileList" :show-file-list="false">
            <el-button style="width: 120px;position: relative;top:-55px;left:260px;" type="danger" class="button">
              上传附件
            </el-button>
          </el-upload>

        </div>
        <!-- <div class="list" > -->
          <!-- 采购合同列表 -->
          <div class="list1" style="height: 100px;">
            <p style="text-align: left;margin-left: 0px;margin-top:30px;border-left: 3px solid #fe0100;height: 25px;">
              <span class="title" style="color:#fe0100 ;font-weight: 500;font-size: 18px;padding-left: 15px;">采购合同列表</span><br>
            <ul style="list-style: none;">
              <li v-model="buyList" style="line-height: 30px;border: 0px solid #000;" @click="Detailbuy(buyList)">
                <div class="title" style="float: left;" v-if="contractData.principalName!=null">
                  <i class="el-icon-paperclip" style="margin-right: 5px;"></i>
                  <a href="">{{buyList.contractName}}</a>
                  <div class="cz" style="margin-left: 30px;float: right;cursor: pointer;">
                    <span>{{(parseFloat(buyList.contractAmount)).toLocaleString('zh-CN', { style: 'currency', currency:
                      'cny', currencyDisplay: 'symbol' })}}</span>
                  </div>
                </div>
                <div v-if="contractData.principalName==null">
                </div>
              </li>
            </ul>
            </p>
          </div>
          <!-- 上传合同 -->
          <div class="list2" style="height: auto;">
            <p style="text-align: left;margin-left: 0px;margin-top:30px;border-left: 3px solid #fe0100;height: 25px;">
              <span class="title"style="color:#fe0100 ;font-weight: 500;font-size: 18px;padding-left: 15px;">文件列表（请上传合同和发票扫描件）</span><br>
            <ul>
              <li v-for="item in fileList" :key="item.fileId" style="line-height: 30px;border: 0px solid #000;">
                <div class="title" style="float: left;"><i class="el-icon-document"
                    style="margin-right: 5px;"></i>{{item.fileTitle}}</div>
                <div class="cz" style="margin-left: 30px;float: right;cursor: pointer;">
                  <i class="el-icon-delete" @click="Remove(item)" style="margin-right: 10px;"></i>
                  <i class="el-icon-download" @click="outputFile(item.fileId,item.fileUrl)"></i>
                </div>
              </li>
            </ul>
            </p>
          </div>
        <!-- </div> -->
        <!-- 合同进度列表 -->
        <div class="tabs" style="border: 0px solid #000;border-radius: 10px;overflow: hidden;">
          <div class="title"
            style="text-align: left;margin-left: 0px;margin-top:30px;border-left: 3px solid #fe0100;width: 300px;height: 25px;">
            <h3 style="color:#fe0100 ;font-weight: 500;font-size: 18px;padding-left: 15px;">合同进度列表</h3>
          </div>
          <el-table :data="scheduleList" stripe style="width: 100%;text-align: center;margin:30px 20px;" :row-style="{height:'48px'} " :cell-style="{padding:'0px'}">
            <el-table-column type="expand">
              <template slot-scope="props">
                <el-form label-position="left" inline class="demo-table-expand">
                 
                  <el-form-item label="票据附件" style="color:  #0060ff;">
                    <ul>
                      <li v-for="(item,index) in fileList1[props.$index]" :key="index">{{item.fileTitle}}
                        <div class="cz" style="margin-left: 30px;float: right;cursor: pointer;">
                           <i class="el-icon-delete" @click="Remove(item)" style="margin-right: 10px;"></i>
                          <i class="el-icon-download" @click="outputFile(item.fileId,item.fileUrl)"></i>
                        </div>
                      </li>
                    </ul>
                  </el-form-item>

                </el-form>
              </template>
            </el-table-column>
            <el-table-column prop="title" label="合同进度" width="120">
            </el-table-column>
            <el-table-column prop="status" label="状态" width="120" :formatter="statusFormat">
            </el-table-column>
            <el-table-column prop="receivableAmount" label="应收账款" width="100" :formatter="amountFormat">
            </el-table-column>
            <el-table-column prop="receivableTime" label="应收日期" width="150" :formatter="dateFormat">
            </el-table-column>
            <el-table-column prop="amount" label="实收账款" width="100" :formatter="amountFormat">
            </el-table-column>
            <el-table-column prop="chargeTime" label="实收日期" width="150" :formatter="dateFormat">
            </el-table-column>
            <el-table-column prop="billAmount" label="发票金额" width="150" :formatter="amountFormat">
            </el-table-column>
            <el-table-column prop="billTime" label="开票日期" width="150" :formatter="dateFormat">
            </el-table-column>
            <!-- <el-table-column prop="billUrl" label="票据附件" width="150" :formatter="dateFormat">
          </el-table-column> -->
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button @click="updateButton(scope.row)" class="cz-button" type="danger" style="margin-top: 25px;"><span style="position: relative;top: -6px;">修改</span></el-button>
                <el-button @click="deleteSchedule(scope.row)" class="cz-button" type="danger"><span style="position: relative;top: -6px;">删除</span></el-button>
                <el-upload class="upload-demo" action="http://192.168.2.75:9050/api/file/upload"
                  :on-preview="uploadVideoProcess1" multiple :on-success="handleVideoSuccess1" :headers='importHeaders1'
                  :file-list="fileList1" :show-file-list="false">
                  <el-button  @click="curRowIndex(scope.row)" class="cz-button" style="width: 100px;position: absolute;top: 10px;left: 190px;" type="danger"><span style="position: relative;top: -6px;">上传附件</span>
                  </el-button>

                </el-upload>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination style="margin:20px;text-align: right;" @current-change="handleCurrentChange" :page-size="size"
            :current-page="current" :total="total" layout="prev, pager, next">
          </el-pagination>
        </div>
        <!-- 合同进度添加 -->
        <div class="add">
          <el-dialog title="合同进度添加" :visible.sync="dialogVisible">
            <el-form>
              <el-form-item label="标题">
                <el-select v-model="scheduleData.title" placeholder="请选择" clearable
                  style="border:1px solid #b6b6b6;width: 300px;border-radius: 50px;overflow: hidden;">
                  <el-option label="预付款" value="预付款"></el-option>
                  <el-option label="进度款" value="进度款"></el-option>
                  <el-option label="质保金" value="质保金"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="应收账款" placeholder="请输入内容">
                <el-input v-model="scheduleData.receivableAmount">
                </el-input>
              </el-form-item>
              <el-form-item label="应收日期" placeholder="请输入内容">
                <el-date-picker v-model="scheduleData.receivableTime">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="实收账款" placeholder="请输入内容">
                <el-input v-model="scheduleData.amount">
                </el-input>
              </el-form-item>
              <el-form-item label="实收日期" placeholder="请输入内容">
                <el-date-picker v-model="scheduleData.chargeTime">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="发票金额" placeholder="请输入内容">
                <el-input v-model="scheduleData.billAmount">
                </el-input>
              </el-form-item>
              <el-form-item label="开票日期" placeholder="请输入内容">
                <el-date-picker v-model="scheduleData.billTime">
                </el-date-picker>
              </el-form-item>
              <!-- <el-form-item label="票据附件" placeholder="请输入内容">
              <el-date-picker v-model="scheduleData.billUrl">
              </el-date-picker>
            </el-form-item> -->
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;margin-bottom: 20px;  cursor: pointer; ">
              <!-- dialogVisible = false -->
              <el-button @click="empty" type="danger" class="button">取 消</el-button>
              <el-button  @click="addSchedule()" type="danger" class="button">添 加</el-button>
            </div>
          </el-dialog>
        </div>
        <!-- 合同进度修改 -->
        <div class="add">
          <el-dialog title="合同进度修改" :visible.sync="dialogVisible1">
            <el-form>
              <el-form-item label="标题"> 
                <el-select v-model="updateRow.title" placeholder="请选择" clearable
                  style="border:1px solid #b6b6b6;width: 300px;border-radius: 50px;overflow: hidden;">
                  <el-option label="预付款" value="0"></el-option>
                  <el-option label="进度款" value="1"></el-option>
                  <el-option label="质保金" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="状态">
                <el-radio-group v-model="updateRow.status">
                  <el-radio label="0">未完成</el-radio>
                  <el-radio label="1">已完成</el-radio>
                </el-radio-group>

              </el-form-item>
              <el-form-item label="应收账款" placeholder="请输入内容">
                <el-input v-model="updateRow.receivableAmount">
                </el-input>
              </el-form-item>
              <el-form-item label="应收日期" placeholder="请输入内容">
                <el-date-picker v-model="updateRow.receivableTime">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="实收账款" placeholder="请输入内容">
                <el-input v-model="updateRow.amount">
                </el-input>
              </el-form-item>
              <el-form-item label="实收日期" placeholder="请输入内容">
                <el-date-picker v-model="updateRow.chargeTime">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="发票金额" placeholder="请输入内容">
                <el-input v-model="updateRow.billAmount">
                </el-input>
              </el-form-item>
              <el-form-item label="开票日期" placeholder="请输入内容">
                <el-date-picker v-model="updateRow.billTime">
                </el-date-picker>
              </el-form-item>
              <!-- <el-form-item label="票据附件" placeholder="请输入内容">
              <el-date-picker v-model="updateRow.billUrl">
              </el-date-picker>
            </el-form-item> -->
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;margin-bottom: 20px; cursor: pointer; ">
              <el-button @click="dialogVisible1 = false" type="danger" class="button">取 消</el-button>
              <el-button @click="updateLinkman()" type="danger" class="button">修改</el-button>
            </div>
          </el-dialog>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import moment from 'moment'
  export default {
    inject: ['reload'],
    data() {
      return {
        goBackCustomFlag: 1,
        dialogVisible: false,
        dialogVisible1: false,
        current: 0,
        size: 100,
        type: 0,
        total: 0,
        contractData: {},
        userList1: [],
        userList: [],
        userList2: [],
        userList3: [],
        changeList: [],
        scheduleList: [],
        fileList: [],
        fileList1: [],
        buyList: [],   //采购合同列表

        contractList: [],
        fileId: '',
        importHeaders: {},
        importHeaders1: {},
        scheduleId: '',
        userType: '',
        salesId: '',
        remark: '', //说明
        contractName: '',
        contractNumber: '',
        contractAmount: '',
        contractDate: '',
        dateDue: '',
        contractStatus: '',
        scheduleData: {
          title: '',
          contractId: '',
          userId: '',
          amount: '',
          describes: '',
          status: '',
          remindTime: '',
          receivableTime: '',
          chargeTime: '',
          receivableAmount: '',
          billAmount: '',
          billTime:''
        },
        fileData: {
          fileUrl: '',
          createTime: '',
          salesId: '',
          userId: this.$cookies.get("userId"),
          fileTitle: '',
          fileType: '',
          remark: this.$route.query.contractId
        },
        fileData1: {
          fileUrl: '',
          createTime: '',
          userId: this.$cookies.get("userId"),
          fileTitle: '',
          fileType: '',
          remark: this.scheduleId
        },
        updateRow: {},
        //编辑
        // activeButton: 0,
        // isEditContract: false, // 编辑机会
      }
    },
    mounted() {
      this.scheduleData.contractId = this.$route.query.contractId
      this.goBackCustomFlag = this.$route.query.goBackCustomFlag
      this.contractId = this.$route.query.contractId,
        this.customId = this.$route.query.customId,
        this.getContractList()
      this.getUserList()
      this.getChangeList()
      this.importHeaders = {
        token: sessionStorage.getItem('token'),
        // Accept: ['application/json', 'text/plain', '*/*']
      };

    },
    methods: {
      moment, //日期时间格式化
      // 金额格式化
      amountFormat: function (row, column) {
        // debugger
        var amount = row[column.property];
        if (amount == undefined) {
          return "";
        }
        return (parseFloat(amount)).toLocaleString('zh-CN', { style: 'currency', currency:
                  'cny', currencyDisplay: 'symbol' });
      },
      handleCurrentChange(val) {
        this.current = val
        this.getScheduleList()
      },
      getScheduleNumber() {
        let j = 0
        for (let i = 0; i < this.scheduleList.length; i++) {
          if (this.scheduleList[i].status == "1") {
            j += 1
          }
        }
        return j
      },
      statusFormat(row, column) {
        switch (column.property) {
          case "status":
            var status = ["未完成", "已完成"]
            var value = status[Number(row[column.property])]
            break;
        }
        return value;
      },
      // 获取合同进度列表
      async getScheduleList() {
        // 解构出参数
        const {
          current,
          size,
          contractId
        } = this;
        var data = {
          contractId: contractId,
          current: current,
          size: size,

        }
        let result = await this.$API.agreement.reqContractSchedule(data);
        // console.log(result)
        this.total = result.data.total;
        this.scheduleList = result.data.data
        this.fileList1 = []
        for (let i = 0; i < this.scheduleList.length; i++) {
          let data = {
            current: 1,
            size: 100,
            remark: this.scheduleList[i].scheduleId,
          }
          let result1 = await this.$API.file.reqFileList(data)
          if (result1.data.code == 200) {
            if (result1.data.data.length != 0) {
              this.fileList1.push(result1.data.data)
            } else {
              this.fileList1.push([])
            }
          } else {
            this.$message.error("查询失败！");
          }

        }
      },
   
      curRowIndex(row) {
        console.log(row)
        this.scheduleList[0] = row;
      },
      // 上传合同进度票据
      handleVideoSuccess1(res1, file1) {                               //获取上传图片地址
        this.fileFlag = false;
        this.fileUploadPercent = 0;
        console.log(res1)
        if (res1.code == 200) {
          this.$message.success('文件上传成功！');
          this.addFile1(file1.name, file1.response.data)
        } else {
          this.$message.error('文件上传失败，请重新上传！');
        }
      },
      uploadVideoProcess1(event1, file1, fileList1) {
        this.fileFlag1 = true;
        this.fileUploadPercent1 = Math.floor(file1.percentage.toFixed(0));
      },
      // 添加票据附件
      addFile1(filename1, fileurl1) {
        this.fileData1.fileTitle = filename1
        this.fileData1.fileUrl = fileurl1
        this.fileData1.remark = this.scheduleList[0].scheduleId
        var data = this.fileData1;
        // console.log(data)
        this.$API.file.reqAddFile(data).then(res => {
          if (res.data.code == 200) {
            this.$message.success("添加成功！");
            this.getScheduleList()
          } else {
            this.$message.error("添加失败！");
          }
        })
      },
      // 删除票据附件
      Remove(res1) {
        console.log(res1);
        console.log('------------------------------');
        console.log(res1.fileId);
        this.$confirm(`确定移除 ${res1.fileTitle}？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            // 移除对应索引位置的数据，可以对row进行设置向后台请求删除数据
            const { fileId } = this;
            var data = {
              fileId: res1.fileId
            }
            let result = this.$API.file.reqDelFile(data);
            // this.fileList.splice(fileList, 1);
            //

            this.$message.success("删除成功！");

            this.getScheduleList()
            this.reload()
          })


      },
      // 下载票据附件
      outputFile(a, b) {
        console.log("---------------------")
        console.log(process.env.VUE_APP_SERVER_HOST + b);
        let link = document.createElement("a");
        link.target = "_blank"
        link.href = process.env.VUE_APP_SERVER_HOST + b;
        link.setAttribute("download", "");
        link.click();

      },
      //跳转回客户
      goBackCustom() {
        this.$router.push({
          path: '/custem/detail',
          name: 'custemDetail',
          query: {
            userId: this.contractData.customId,
          }
        });
      },
      goBackP() {
        // if (this.parentId == 0 || this.parentId == null) {
        //   const tolink = this.$router.push({
        //     path: '/agreement',
        //   });
        //   window.open(tolink.href, '_self')
        // } else {
          this.$router.go(-1)
        // }

      },
      // 采购合同列表跳转
      Detailbuy(a) {
        const tolink = this.$router.push({
          path: '/agreementDetails',
          query: { contractId: a.contractId }
        });
        window.open(tolink.href, '_self')
      },
      //上传附件
      handleVideoSuccess(res, file) { //获取上传图片地址
        this.fileFlag = false;
        this.fileUploadPercent = 0;
        console.log(file)
        if (res.code == 200) {
          this.$message.success('文件上传成功！');
          this.addFile(file.name, file.response.data)
        } else {
          this.$message.error('文件上传失败，请重新上传！');
        }
      },
      uploadVideoProcess(event, file, fileList) {
        this.fileFlag = true;
        this.fileUploadPercent = Math.floor(file.percentage.toFixed(0));
      },
      // 删除附件
      Remove(res) {
        // console.log(res);

        this.$confirm(`确定移除 ${res.fileTitle}？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            // 移除对应索引位置的数据，可以对row进行设置向后台请求删除数据
            const {
              fileId
            } = this;
            var data = {
              fileId: res.fileId
            }
            let result = this.$API.file.reqDelFile(data);
            // this.fileList.splice(fileList, 1);
            // this.reload();
            this.getFileList()
            this.$message.success("删除成功！");
          })


      },
      // 下载附件
      outputFile(a, b) {
        console.log("---------------------")
        console.log(process.env.VUE_APP_SERVER_HOST + b);
        let link = document.createElement("a");
        link.target = "_blank"
        link.href = process.env.VUE_APP_SERVER_HOST + b;
        link.setAttribute("download", "");
        link.click();
      },
      //  编辑确定
      updateContract() {
        var data = this.contractData
        // 获取资源列表接口
        this.$API.agreement.reqUpdataContract(data).then(res => {
          if (res.data.code == 200) {
            this.$message.success("修改成功！");
            this.type = 0
            this.getContractList()
          } else {
            this.$message.error("修改失败！");
          }
        })
      },
      
      
      // 获取机会列表
      async getChangeList() {
        // 解构出参数
        // const {
        //   current,
        //   size
        // } = this;
        var data = {
          current: 1,
          size: 100,
        }
        let result = await this.$API.change.reqChangeList(data)
        // this.total = result.data.total;
        this.changeList = result.data.data
      },
      // 获取合同信息
      getContractList() {
        var data = {
          current: 1,
          size: 100,
          contractId: this.contractId,
        }
        this.$API.agreement.reqContractList(data).then(res => {
          if (res.data.code == 200) {
            if (res.data.data.length != 0) {
              this.contractData = res.data.data[0]
              this.getScheduleList()
              this.getFileList()
              this.getMainContractList()
              this.getBuyContractList()
            } else {
              this.contractData = []
            }
          } else {
            this.$message.error("查询失败！");
          }
        })

      },
      // 主合同
      getMainContractList() {
        var data = {
          current: 1,
          size: 100,
          // contractStatus: '1',
          contractType: '0'
        }
        this.$API.agreement.reqContractList(data).then(res => {
          if (res.data.code == 200) {
            this.contractList = res.data.data
          } else {
            this.$message.error("查询失败！");
          }
        })
      },
      // 采购合同
      getBuyContractList() {
        var data = {
          current: 1,
          size: 100,
          parentId: this.contractData.contractId,
          contractType: '1'
        }
        this.$API.agreement.reqContractList(data).then(res => {
          if (res.data.code == 200) {
            if (res.data.data.length != 0) {
              this.buyList = res.data.data[0]
              // console.log(this.agreList)
            } else {
              this.buyList = []
            }

          } else {
            this.$message.error("查询失败！");
          }
        })
      },
      //获取文件列表
      getFileList() {
        var data = {
          current: 1,
          size: 100,
          remark: this.contractId,
        }
        this.$API.file.reqFileList(data).then(res => {
          if (res.data.code == 200) {
            if (res.data.data.length != 0) {
              this.fileList = res.data.data
            } else {
              this.fileList = []
            }
          } else {
            this.$message.error("查询失败！");
          }
        })
      },
      // 添加文件
      addFile(filename, fileurl) {
        this.fileData.fileTitle = filename
        this.fileData.fileUrl = fileurl
        var data = this.fileData;
        console.log("添加合同文件")
        this.$API.file.reqAddFile(data).then(res => {
          if (res.data.code == 200) {
            this.$message.success("添加成功！");
            this.getFileList();
          } else {
            this.$message.error("添加失败！");
          }
        })

      },

      // stateFormat(row, column) {
      //   if (row.status == 0) {
      //     return '未完成'
      //   } else if (row.status == 1) {
      //     return '已完成'
      //   }
      // },
      //时间格式化
      dateFormat: function (row, column) {
        // debugger
        var date = row[column.property];
        if (date == undefined) {
          return "";
        }
        return moment(date).format("YYYY/MM/DD");
      },
      // 添加合同进度
      addSchedule() {
        var data = this.scheduleData;
        if (data.title == '') {
          this.$message("联系人名称不能为空")
        } else {
          this.$API.agreement.reqAddSchedule(data).then(res => {
            if (res.data.code == 200) {
              this.$message.success("添加成功！");
              this.dialogVisible = false;
              this.getScheduleList();
            } else {
              this.$message.error("添加失败！");
            }
          })
        }
      },
      // 取消添加
      empty(){
        this.scheduleData.title=""       
        this.scheduleData.amount=""
        this.scheduleData.billTime=""
        this.scheduleData.receivableTime=""
        this.scheduleData.chargeTime=""
        this.scheduleData.receivableAmount=""
        this.scheduleData.billAmount=""
        this.dialogVisible = false


        
      },
      updateButton(row) {
        // console.log(row)
        this.updateRow = row;
        this.dialogVisible1 = true;
      },
      //修改联系人
      updateLinkman() {
        var data = this.updateRow
        this.$API.agreement.reqUpdataSchedule(data).then(res => {
          if (res.data.code == 200) {
            this.$message.success("修改成功！");
            this.dialogVisible1 = false;
            this.getScheduleList()
          } else {
            this.$message.error("修改失败！");
          }
        })
      },
      // 删除联系人
      deleteSchedule(row) {
        this.$confirm("确认删除此进度？", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          var data = {
            scheduleId: row.scheduleId
          }
          this.$API.agreement.reqDelSchedule(data).then(res => {
            if (res.data.code == 200) {
              this.$message.success("删除成功！");
              this.getScheduleList()
            } else {
              this.$message.error("删除失败！");
            }
          })
        })
      },
      // 获取客户列表
      async getUserList() {
        // 解构出参数
        const {
          current,
          size,
          userType,
          userId
        } = this;
        var data = {
          current: 1,
          size: 100,
          userType: "23",
          userId: this.customId
        }
        var data1 = {
          current: 1,
          size: 100,
          userType: "1",
          userId: this.secondRepresentative
        }
        var data2 = {
          current: 1,
          size: 100,
          userType: "23",

        }
        var data3 = {
          current: 1,
          size: 100,
          userType: "1",

        }
        let result = await this.$API.user.reqUserList(data)
        // this.total = result.data.total;
        this.userList = result.data.data
        let result1 = await this.$API.user.reqUserList(data1)
        // this.total = result1.data.total;
        this.userList1 = result1.data.data
        let result2 = await this.$API.user.reqUserList(data2)
        // this.total = result2.data.total;
        this.userList2 = result2.data.data
        let result3 = await this.$API.user.reqUserList(data3)
        // this.total = result3.data.total;
        this.userList3 = result3.data.data
      },
      handleClick(tab, event) {
        // console.log(tab, event);
      }
    },
  }

</script>
<style scoped>
  @import "../../../style/style.css";

  .bx>>>.el-form-item__content {
    width: 300px !important;
    /* border: 1px solid #000; */
  }

  .bx>>>.el-form-item__label {
    font-size: 16px;
  }

  .bx>>>.el-textarea__inner {
    height: 150px;
    /* margin-left: 90px; */
    border: 1px solid #b6b6b6;
    border-radius: 10px;
    overflow: hidden;
    width: 300px;
    position: relative;
    top: 0;
  }

  .bx>>>.el-input__suffix {
    left: 150px;
  }

  .bx>>>.el-form-item {
    margin-bottom: 10px;
  }

  .bx ul li p .title {
    color: #888;
    margin-right: 20px;
    /* position: relative;
    top: -15px; */
  }

  .bx ul li p .blue {
    color: #fe0100;
    /* margin-right: 20px; */
  }

  .bx>>>.el-select .el-input {
    width: 100%;
  }

  .bx>>>.el-input__suffix {
    text-align: right;
  }

  .el-input,
  .el-select,
  .el-date-picker {
    border: 1px solid #b6b6b6;
    border-radius: 50px;
    overflow: hidden;
    width: 300px;
    position: relative;
    top: 0;
  }

  .el-button {
    margin-top: 15px;
  }

  .add>>>.el-dialog {
    position: relative;
    margin: 0 auto 50px;
    border-radius: 15px;
    box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
    box-sizing: border-box;
    width: 500px;
    overflow: hidden;
  }

  .add>>>.el-input__suffix {
    text-align: right;
  }

  .add>>>.el-select .el-input {
    width: 100%;
  }

  .add>>>.el-form-item__content {
    text-align: right;
    padding-right: 50px;
  }

  .add>>>.el-radio-group {
    margin-right: 100px;
  }

  .demo-table-expand {
    font-size: 0;
  }

  .demo-table-expand label {
    width: 200px;
    color: #99a9bf;
  }

  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
    margin-left: 60px;
  }

  .tabs>>>.el-button--primary {
    position: absolute;
    margin-left: 180px;
    margin-top: -55px;
  }

  .tabs>>>.el-form-item__label {
    color: #0060ff;

  }
</style>